<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <script>
            //1.基本格式
            var person = {"name": "张三", "age": 20, "gender": "男"};
            //var name = person.name;
            var name = person["name"];
            // alert(name);
            //遍历person对象中所有的键和值
            /*//for in循环
            for (var key in person){
              alert(key+":"+person[key]);

            }*/


            //2.嵌套格式
            var persons = [
                {"name": "张三", "age": 20, "gender": "男"},
                {"name": "李四", "age": 21, "gender": "男"},
                {"name": "王五", "age": 22, "gender": "男"}
            ];
            var name1 = persons[1].name;
            //  alert(name1);
            //遍历persons对象中所有的键和值
            //for in循环
            /*  for (var i = 0; i <persons.length ; i++) {
                  var p = persons[i];
                  for (var key in p){
                      alert(key+":"+p[key]);

                  }
              }*/

            var human = {
                "ps": [
                    {"name": "张三", "age": 20, "gender": "男"},
                    {"name": "李四", "age": 21, "gender": "男"},
                    {"name": "王五", "age": 22, "gender": "男"}],
                "ps1": [
                    {"name": "赵六", "age": 20, "gender": "男"},
                    {"name": "田七", "age": 21, "gender": "男"}]

            };
            var name2 = human.ps[2].name;
            // alert(name2);

            //遍历human对象中所有的键和值
            //for in循环
            for (var key in human) {
                var ps = human[key];
                for (let i = 0; i < ps.length; i++) {
                    var p = ps[i];
                    for (var pKey in p) {
                        alert(pKey + ":" + p[pKey]);
                    }

                }
            }


        </script>
    </body>
</html>